///<reference path="../typings/index.d.ts"/>
import express = require('express');
import bodyParser = require('body-parser');
import file = require('fs');
import path = require('path');
import { fstat } from 'fs';
import { json } from 'body-parser';
import { exec } from 'child_process';
import { FXCMSocketIO, FXCMData } from "../FMCode/FXCMData"
import { FXNewsManager } from "../fxline/FXNews"
import { APITest } from '../FMAppAPI/APITest';
import { APIRequestType } from '../FMAppAPI/Core/FMAppAPIConstant';
const app = express();
var httpServer = require('http').createServer(app);
let socketServer: SocketIO.Server = require("socket.io").listen(httpServer);
app.use(bodyParser.raw());
app.use((err, req, res, next) => {
    console.log("service error");
    console.log(err.stack);
    res.status(500).send("some error");
});
app.use(express.static('js'));
console.log("xinbaby");
const jsonParser = bodyParser.json();
app.get('/tushare', jsonParser, (req, res) => {
    console.log(req.body);
    //  var readFile = file.createReadStream('C:\\Users\\xin\\Downloads\\App需求\\com.jojogold.hk.apk')

    const apk = file.readFileSync('C:\\Users\\xin\\Downloads\\App需求\\com.jojogold.hk.apk', 'binary');
    res.download('C:\\Users\\xin\\Downloads\\App需求\\AX88179_178A_Macintosh_10.6_to_10.13_Driver_Installer_v2.9.0_20170426.zip');
    // res.end();
});
app.get('/notification', (req, res) => {
    const html = file.readFileSync('../FMCode/chrome-notifiction.html', 'utf-8');
    res.send(html);
    res.end();
})

httpServer.listen(9960, () => {
    console.log("data center service start listen port 9960");
});
// socketServer.use((client,next)=>{
//     console.log(client);
//     next();
// });
socketServer.on("connection", (socket) => {
    console.log("socket client connected");
});
function startConnectTickData() {
    const tickServer = new FXCMSocketIO();
    tickServer.connectToServer((tickData) => {
        console.log(tickData);
        if (tickData.ask > 1268) {
            socketServer.sockets.emit("data", JSON.stringify(tickData));
        }
    });
}

function test(){
   var test = new APITest();
    test.loginTest();
}
test();
startConnectTickData();
let newsManager = new FXNewsManager();
newsManager.getNewsFromJIN10();